from collections import defaultdict


def word_count(words: str):
    words_count = defaultdict(int)
    for word in words:
        words_count[word] += 1

    return words_count


def sort_word_count(words: str):
    words_count = word_count(words)
    sorted_words_count = sorted(words_count.items(),
                                key=lambda item: item[1], reverse=True)
    return sorted_words_count


if __name__ == '__main__':
    print(word_count('abdcbdaddfnc'))
    print(sort_word_count('abdcbdaddfnc')[:3])

# 用到了函数与规范的python开发书写，不错。不过第二个结果可以考虑使用枚举打印出来
